package com.sand.controller;

import com.sand.dto.Owner.MerchantOrOwner;
import com.sand.dto.merchant.ContractAdd;
import com.sand.dto.merchant.ContractSelect;
import com.sand.entity.conclude.contract;
import com.sand.result.ResponseResult;
import com.sand.service.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//合同
@RestController
@RequestMapping("/contract")
public class ContractController {

    @Autowired
    private ContractService contractService;


    /**
     * 签订合同
     */
    @PostMapping("/add")
    public ResponseResult<Integer> add(@RequestBody ContractAdd contractAdd){
        Integer i = contractService.add(contractAdd);
        return new ResponseResult<Integer>().ok(i);
    }

    /**
     * 查看商家或客户的一个所有合同
     */
    @PostMapping("/list")
    public ResponseResult<List<contract>> GetList(@RequestBody MerchantOrOwner merchantOrOwner){
        List<contract> list = contractService.Getlist(merchantOrOwner);
        return new ResponseResult<List<contract>>().ok(list);
    }

    /**
     * 查看合同详细信息
     */
    @PostMapping("/getall")
    public ResponseResult<ContractSelect> getall(@RequestBody Integer contractid){
         ContractSelect contractSelect =  contractService.getall(contractid);
         return new ResponseResult<ContractSelect>().ok(contractSelect);
    }

    /**
     * 根据id查看合同
     */
    @PostMapping("/get")
    public ResponseResult<contract> get(@RequestBody Integer id){
        return new ResponseResult<contract>().ok(contractService.get(id));
    }

    /**
     * 完成合同
     */
    @PostMapping("/ok")
    public ResponseResult<Integer> ok(@RequestBody Integer contractid){
        Integer i = contractService.ok(contractid);
        return new ResponseResult<Integer>().ok(i);
    }

}
